-- 水落汇川
local shuiluohuichuan = fk.CreateSkill {
    name = "mcdh_shuiluohuichuan",
    tags = {Skill.Compulsory}
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

shuiluohuichuan:addEffect(fk.Damage,{
    can_trigger = function(self, event, target, player, data)
        if not player:hasSkill(self) then return false end
        return target == player and player.phase == Player.NotActive
    end,
    on_trigger = function(self, event, target, player, data)
        for _ = 1, data.damage do
            if  not player:hasSkill(self) then break end
            self:doCost(event, target, player, data)
        end
    end,
    on_use = function(self, event, target, player, data)
        local room =player.room
        player:drawCards(1,self.name)
    end
})

shuiluohuichuan:addEffect(fk.Damaged,{
    can_trigger = function(self, event, target, player, data)
        if not player:hasSkill(self) then return false end
        return target == player and player.phase == Player.NotActive
    end,
    on_trigger = function(self, event, target, player, data)
        for _ = 1, data.damage do
            if  not player:hasSkill(self) then break end
            self:doCost(event, target, player, data)
        end
    end,
    on_use = function(self, event, target, player, data)
        local room =player.room
        player:drawCards(1,self.name)
    end
})

shuiluohuichuan:addEffect(fk.EventPhaseStart,{
    can_trigger = function(self, event, target, player, data)
        if not player:hasSkill(self) then return false end
        return target ~= player and target.phase == Player.Start and #target:getPile("mcdh_lu") > 0
    end,
    on_use = function(self, event, target, player, data)
        local room =player.room
        local num = #target:getPile("mcdh_lu")
        room:moveCardTo(target:getPile("mcdh_lu"), Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, "mcdh_lu", true, player.id)
        for i=1,num,1 do
            if player.dead or target.dead then break end
            room:useVirtualCard("slash", nil, player, target, self.name, false)
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_shuiluohuichuan"] = "水落匯川",
    [":mcdh_shuiluohuichuan"] = "锁定技，当你于回合外造成或受到1点伤害后，摸一张牌。其他角色的准备阶段，你移去其所有「露」并视为对其使用等量张【杀】。",
}

return shuiluohuichuan